﻿using SelfMadeMillionaire.Core.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;

namespace SelfMadeMillionaire.Core.Entities
{
	public class EmailMessage : BaseEntity
	{
		[StringLength(100)]
		public string Title { get; set; }
		public string Body { get; set; }
		public DateTime? DateSent { get; set; }
		public byte ProductType { get; set; }
		public byte MinAccessLevel { get; set; }

		public virtual ICollection<Subscriber> Subscribers { get; set; }

		public virtual ICollection<EmailMessageSchedule> Schedules { get; set; }

        public DateTime? FreeSendDate { get; set; }
        public byte FreeSendStatus { get; set; }

        public DateTime? SilverSendDate { get; set; }
        public byte SilverSendStatus { get; set; }

        public DateTime? GoldSendDate { get; set; }
        public byte GoldSendStatus { get; set; }

        public DateTime? PlatinumSendDate { get; set; }
        public byte PlatinumSendStatus { get; set; }


        bool IsMMMMessage()
        {
            return (ProductType == (byte)SelfMadeMillionaire.Core.Enums.ProductType.MaggiesMoneyMountain);
        }

        public bool IsSMMMessage()
        {
            return (ProductType == (byte)SelfMadeMillionaire.Core.Enums.ProductType.SelfMadeMillionaire);
        }

        bool IsFreeLevel()
        {
            return MinAccessLevel <= (byte)SubscriptionType.Free;
        }        

        bool IsSilverLevel()
        {
            return MinAccessLevel <= (byte)SubscriptionType.Silver;
        }

        bool IsGoldLevel()
        {
            return MinAccessLevel <= (byte)SubscriptionType.Gold;
        }

        bool IsPlatinumLevel()
        {
            return MinAccessLevel <= (byte)SubscriptionType.Platinum;
        }

        public bool SendMeToFreeMMMSubscribers()
        {
            return IsMMMMessage() && FreeSendDate.HasValue && FreeSendDate.Value <= DateTime.Now && FreeSendStatus == (byte)SendStatus.None;
        }

        public bool SendMeToFreeSMMSubscribers()
        {
            return IsSMMMessage() && IsFreeLevel() && FreeSendDate.HasValue && FreeSendDate.Value <= DateTime.Now && FreeSendStatus == (byte)SendStatus.None;
        }

        public bool SendMeToSilverSubscribers()
        {
            return !IsMMMMessage() && IsSilverLevel() && SilverSendDate.HasValue && SilverSendDate.Value <= DateTime.Now && SilverSendStatus == (byte)SendStatus.None;
        }

        public bool SendMeToGoldSubscribers()
        {
            return !IsMMMMessage() && IsGoldLevel() && GoldSendDate.HasValue && GoldSendDate.Value <= DateTime.Now && GoldSendStatus == (byte)SendStatus.None;
        }

        public bool SendMeToPlatinumSubscribers()
        {
            return !IsMMMMessage() && IsPlatinumLevel() && PlatinumSendDate.HasValue && PlatinumSendDate.Value <= DateTime.Now && PlatinumSendStatus == (byte)SendStatus.None;
        }
    }
}
